// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.
#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]

/// Implements a client for the Cloud Domains API.
///
/// # Example
/// ```
/// # tokio_test::block_on(async {
/// # use google_cloud_domains_v1::client::Domains;
/// let client = Domains::builder().build().await?;
/// // use `client` to make requests to the Cloud Domains API.
/// # gax::client_builder::Result::<()>::Ok(()) });
/// ```
///
/// # Service Description
///
/// The Cloud Domains API enables management and configuration of domain names.
///
/// # Configuration
///
/// To configure `Domains` use the `with_*` methods in the type returned
/// by [builder()][Domains::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://domains.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::domains::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::domains::ClientBuilder::credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `Domains` holds a connection pool internally, it is advised to
/// create one and the reuse it.  You do not need to wrap `Domains` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct Domains {
    inner: std::sync::Arc<dyn super::stub::dynamic::Domains>,
}

impl Domains {
    /// Returns a builder for [Domains].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_domains_v1::client::Domains;
    /// let client = Domains::builder().build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> super::builder::domains::ClientBuilder {
        gax::client_builder::internal::new_builder(super::builder::domains::client::Factory)
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::Domains + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::Domains>> {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::Domains> {
        super::transport::Domains::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::Domains> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::Domains::new)
    }

    /// Searches for available domain names similar to the provided query.
    ///
    /// Availability results from this method are approximate; call
    /// `RetrieveRegisterParameters` on a domain before registering to confirm
    /// availability.
    pub fn search_domains(&self) -> super::builder::domains::SearchDomains {
        super::builder::domains::SearchDomains::new(self.inner.clone())
    }

    /// Gets parameters needed to register a new domain name, including price and
    /// up-to-date availability. Use the returned values to call `RegisterDomain`.
    pub fn retrieve_register_parameters(
        &self,
    ) -> super::builder::domains::RetrieveRegisterParameters {
        super::builder::domains::RetrieveRegisterParameters::new(self.inner.clone())
    }

    /// Registers a new domain name and creates a corresponding `Registration`
    /// resource.
    ///
    /// Call `RetrieveRegisterParameters` first to check availability of the domain
    /// name and determine parameters like price that are needed to build a call to
    /// this method.
    ///
    /// A successful call creates a `Registration` resource in state
    /// `REGISTRATION_PENDING`, which resolves to `ACTIVE` within 1-2
    /// minutes, indicating that the domain was successfully registered. If the
    /// resource ends up in state `REGISTRATION_FAILED`, it indicates that the
    /// domain was not registered successfully, and you can safely delete the
    /// resource and retry registration.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn register_domain(&self) -> super::builder::domains::RegisterDomain {
        super::builder::domains::RegisterDomain::new(self.inner.clone())
    }

    /// Gets parameters needed to transfer a domain name from another registrar to
    /// Cloud Domains. For domains managed by Google Domains, transferring to Cloud
    /// Domains is not supported.
    ///
    /// Use the returned values to call `TransferDomain`.
    pub fn retrieve_transfer_parameters(
        &self,
    ) -> super::builder::domains::RetrieveTransferParameters {
        super::builder::domains::RetrieveTransferParameters::new(self.inner.clone())
    }

    /// Transfers a domain name from another registrar to Cloud Domains.  For
    /// domains managed by Google Domains, transferring to Cloud Domains is not
    /// supported.
    ///
    /// Before calling this method, go to the domain's current registrar to unlock
    /// the domain for transfer and retrieve the domain's transfer authorization
    /// code. Then call `RetrieveTransferParameters` to confirm that the domain is
    /// unlocked and to get values needed to build a call to this method.
    ///
    /// A successful call creates a `Registration` resource in state
    /// `TRANSFER_PENDING`. It can take several days to complete the transfer
    /// process. The registrant can often speed up this process by approving the
    /// transfer through the current registrar, either by clicking a link in an
    /// email from the registrar or by visiting the registrar's website.
    ///
    /// A few minutes after transfer approval, the resource transitions to state
    /// `ACTIVE`, indicating that the transfer was successful. If the transfer is
    /// rejected or the request expires without being approved, the resource can
    /// end up in state `TRANSFER_FAILED`. If transfer fails, you can safely delete
    /// the resource and retry the transfer.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn transfer_domain(&self) -> super::builder::domains::TransferDomain {
        super::builder::domains::TransferDomain::new(self.inner.clone())
    }

    /// Lists the `Registration` resources in a project.
    pub fn list_registrations(&self) -> super::builder::domains::ListRegistrations {
        super::builder::domains::ListRegistrations::new(self.inner.clone())
    }

    /// Gets the details of a `Registration` resource.
    pub fn get_registration(&self) -> super::builder::domains::GetRegistration {
        super::builder::domains::GetRegistration::new(self.inner.clone())
    }

    /// Updates select fields of a `Registration` resource, notably `labels`. To
    /// update other fields, use the appropriate custom update method:
    ///
    /// * To update management settings, see `ConfigureManagementSettings`
    /// * To update DNS configuration, see `ConfigureDnsSettings`
    /// * To update contact information, see `ConfigureContactSettings`
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn update_registration(&self) -> super::builder::domains::UpdateRegistration {
        super::builder::domains::UpdateRegistration::new(self.inner.clone())
    }

    /// Updates a `Registration`'s management settings.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn configure_management_settings(
        &self,
    ) -> super::builder::domains::ConfigureManagementSettings {
        super::builder::domains::ConfigureManagementSettings::new(self.inner.clone())
    }

    /// Updates a `Registration`'s DNS settings.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn configure_dns_settings(&self) -> super::builder::domains::ConfigureDnsSettings {
        super::builder::domains::ConfigureDnsSettings::new(self.inner.clone())
    }

    /// Updates a `Registration`'s contact settings. Some changes require
    /// confirmation by the domain's registrant contact .
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn configure_contact_settings(&self) -> super::builder::domains::ConfigureContactSettings {
        super::builder::domains::ConfigureContactSettings::new(self.inner.clone())
    }

    /// Exports a `Registration` resource, such that it is no longer managed by
    /// Cloud Domains.
    ///
    /// When an active domain is successfully exported, you can continue to use the
    /// domain in [Google Domains](https://domains.google/) until it expires. The
    /// calling user becomes the domain's sole owner in Google Domains, and
    /// permissions for the domain are subsequently managed there. The domain does
    /// not renew automatically unless the new owner sets up billing in Google
    /// Domains.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn export_registration(&self) -> super::builder::domains::ExportRegistration {
        super::builder::domains::ExportRegistration::new(self.inner.clone())
    }

    /// Deletes a `Registration` resource.
    ///
    /// This method works on any `Registration` resource using [Subscription or
    /// Commitment billing](/domains/pricing#billing-models), provided that the
    /// resource was created at least 1 day in the past.
    ///
    /// For `Registration` resources using
    /// [Monthly billing](/domains/pricing#billing-models), this method works if:
    ///
    /// * `state` is `EXPORTED` with `expire_time` in the past
    /// * `state` is `REGISTRATION_FAILED`
    /// * `state` is `TRANSFER_FAILED`
    ///
    /// When an active registration is successfully deleted, you can continue to
    /// use the domain in [Google Domains](https://domains.google/) until it
    /// expires. The calling user becomes the domain's sole owner in Google
    /// Domains, and permissions for the domain are subsequently managed there. The
    /// domain does not renew automatically unless the new owner sets up billing in
    /// Google Domains.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn delete_registration(&self) -> super::builder::domains::DeleteRegistration {
        super::builder::domains::DeleteRegistration::new(self.inner.clone())
    }

    /// Gets the authorization code of the `Registration` for the purpose of
    /// transferring the domain to another registrar.
    ///
    /// You can call this method only after 60 days have elapsed since the initial
    /// domain registration.
    pub fn retrieve_authorization_code(
        &self,
    ) -> super::builder::domains::RetrieveAuthorizationCode {
        super::builder::domains::RetrieveAuthorizationCode::new(self.inner.clone())
    }

    /// Resets the authorization code of the `Registration` to a new random string.
    ///
    /// You can call this method only after 60 days have elapsed since the initial
    /// domain registration.
    pub fn reset_authorization_code(&self) -> super::builder::domains::ResetAuthorizationCode {
        super::builder::domains::ResetAuthorizationCode::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn list_operations(&self) -> super::builder::domains::ListOperations {
        super::builder::domains::ListOperations::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn get_operation(&self) -> super::builder::domains::GetOperation {
        super::builder::domains::GetOperation::new(self.inner.clone())
    }
}
